<template>
    <van-nav-bar title="详情" />
    <div v-html="detailData.goods_introduce"></div>
    <van-action-bar>
  <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
  <van-action-bar-icon icon="cart-o" text="购物车" />
  <van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
  <van-action-bar-button type="warning" text="加入购物车" @click="add"/>
  <van-action-bar-button type="danger" text="立即购买" />
</van-action-bar>


</template>

<script setup>
import {ref} from 'vue'
import { detailApi } from '@/api/api';
import { useRoute } from 'vue-router';
let route=new useRoute()

let detailData=ref([])
detailApi(route.params.goods_id).then((res)=>{
    console.log('详情数据',res)
    detailData.value=res.data.message
})

//跳转
import { useRouter } from 'vue-router';
let router=new useRouter()
import { showToast } from "vant";
import { useCounterStore } from '@/store/cart'
// 可以在组件中的任意位置访问 `store` 变量 ✨
const store = useCounterStore()

const add=()=>{
    let token=localStorage.getItem('token')
    if(!token){
        showToast({
        type: "fail",
        message: "请先登录",
        duration: 2000,
        onClose() {
          router.push("/login");
        },
      });
    }
    else{
        store.addCart(detailData.value,route.params.goods_id)
    }
    router.push('/home/shop')
}
</script>

<style lang="scss" scoped>

</style>